package myadmin.jtthink.com.MyHelper;

import java.lang.reflect.Parameter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ServiceUtil {
    public static String ucfirst(String str) {
        //首字母大写
        char[] chars = str.toCharArray();
        if (chars[0] >= 'a' && chars[0] <= 'z') {
            chars[0] = (char) (chars[0] - 32);
        }
        return new String(chars);
    } //首字母大写
    public static String camelCase(String str) {
        str = str.toLowerCase();
        Matcher matcher = Pattern.compile("_(\\w)").matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    } //snakecase转化为驼峰
    public static String snakeCase(String str) { //把
        Matcher matcher = Pattern.compile("[A-Z]").matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    } //驼峰转为sc带下划线
    public static Object convertQuery(Parameter parameter, Object value) throws Exception {
        String tName=parameter.getType().getName();
        switch (tName)
        {
            case "int":
                return Integer.parseInt(value.toString());
            case "String":
                return value.toString();
             default:
                throw new Exception("unsupport params");
        }
    }
}
